/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util.jQueryForm.Dialog;

import util.Constant.ConstantjQueryDialogState;
import java.util.LinkedHashMap;
import java.util.Map;
import util.Constant.Constant;
import util.Constant.ConstantjQueryIcon;

/**
 *
 * @author nchanwut
 */
public class jQueryFormDialogOption {

    // <editor-fold defaultstate="collapsed" desc="Param">
    private LinkedHashMap<String, String> mapDialogOption;
    private String _uiState = "";
    private String _uiIcon = "";
    private String _msgTitle = "";
    private String _msgContent = "";
    private String _isOpen = "1"; //Default : Ture = open dialog
    // </editor-fold>

    public jQueryFormDialogOption(Constant dialogTitle, ConstantjQueryDialogState dialogState) { //บังคับใส่ title, state
        setTitle(dialogTitle);
        setState(dialogState);
    }

    /**
     * Status of dialog such as Complete, Error, Warning, Confirm
     * @param ConstantjQueryDialogState : is Enum for control state of dialog
     */
    private jQueryFormDialogOption setState(ConstantjQueryDialogState dialogState) {
        _uiState = ConstantjQueryDialogState.valueOf(dialogState.name()).toString();
        return this;
    }

    /**
     * Icon of dialog
     * @param ConstantjQueryIcon : Complete=circle-check, Error=circle-close, Warning=alert, Confirm=help
     */
    private jQueryFormDialogOption setIcon(ConstantjQueryIcon dialogIcon) {
        _uiIcon = ConstantjQueryIcon.valueOf(dialogIcon.name()).toString();
        return this;
    }

    private jQueryFormDialogOption setTitle(Constant dialogTitle) {
        _msgTitle = Constant.valueOf(dialogTitle.name()).toString();
        return this;
    }

    private jQueryFormDialogOption setContent(Constant dialogContent) {
        _msgContent = Constant.valueOf(dialogContent.name()).toString();
        return this;
    }

    /*
     * Default is Open = true
     * ถ้าเป็น true เปิด dialog : false ไม่ทำอะไร
     */
    private jQueryFormDialogOption setIsOpen(boolean isOpen) {
        _isOpen = (isOpen) ? "1" : "0";
        return this;
    }

    public Map<String, String> getMapDialog() {
        mapDialogOption = new LinkedHashMap<String, String>();
        //หมายเหตุ : ต้อง put เรียงลำดับด้วย
        if (!_uiState.isEmpty()) {
            mapDialogOption.put("uiState", _uiState);
        }
        if (!_uiIcon.isEmpty()) {
            mapDialogOption.put("uiIcon", _uiIcon);
        }
        if (!_msgTitle.isEmpty()) {
            mapDialogOption.put("msgTitle", _msgTitle);
        }
        if (!_msgContent.isEmpty()) {
            mapDialogOption.put("msgContent", _msgContent);
        }
        if (!_msgTitle.isEmpty()) { //เช็คว่ามี title หรือไม่
            mapDialogOption.put("isOpen", _isOpen);
        }
        return mapDialogOption;
    }
}
